<?php

class Pagination
{
    private $_size;
    private $_curr;
    private $_data;

    public function Pagination($data) {
        $this->_size = 10;
        $this->_curr = 1;
        $this->_data = $data;
    }

    public function setPagesize($size) {
        $this->_size = $size;
    }

    public function setCurr($currpage) {
        if ($currpage > $this->pageCount()) {
            $currpage = $this->_curr;
        } else if ($currpage < 1) {
            $currpage = 1;
        }
        $this->_curr = $currpage;
    }

    public function itemCount() {
        return count($this->_data);
    }

    public function pageCount() {
        $result = $this->itemCount() / $this->pagesize();
        if ($this->itemCount() % $this->pagesize() != 0)
            $result += 1;
        return intval($result);
    }

    public function hasNext() {
        return $this->_curr != $this->pageCount();
    }
    public function hasPrevious() {
        return $this->_curr != 1;
    }

    public function curr() {
        return $this->_curr;
    }
    public function next() {
        if ($this->hasNext())
            return $this->_curr + 1;
        return $this->_curr;
    }
    public function previous() {
        if ($this->hasPrevious())
            return $this->_curr - 1;
        return $this->_curr;
    }

    public function pagesize() {
        return $this->_size;
    }

    public function data() {
        $pos = $this->_size * ($this->_curr - 1);
        $len = min($this->itemCount() - $pos, $this->_size);
        return array_slice($this->_data, $pos, $len);
    }

    public function allData() {
        return $this->_data;
    }

}




